package com.zegome.game.gomestory.main.scene.play.board;

import com.zegome.game.gomestory.main.A;

public class SelectProcessor {
	
	Board board;
	
	Pikachu item1, item2;	
	int typePikaLast;
	int combo;
	
	public SelectProcessor(Board board)
	{
		this.board = board;
	}
	
	public void reset(){
		typePikaLast = -1;
		combo = 0;		
		item1 = null;
		item2 = null;		
		typePikaLast = -1;
		combo = 0;	
	}
	
	public void click(Pikachu item){
		if(item1!=null){
			
			item2 = item;
			
			if(item1.col==item2.col&&item1.row==item2.row){				
				board.dataMap.map[item1.row][item1.col].setSelect(false);				
				item1 = item2;
				item2 = null;
				board.dataMap.map[item1.row][item1.col].setSelect(true);	
			}			
			else{
				if(board.dataMap.map[item1.row][item1.col].type==board.dataMap.map[item2.row][item2.col].type&&board.dataMap.map[item1.row][item1.col].type!=-1){
					if(board.checkEat.checkEat(item1.row, item1.col, item2.row, item2.col,true)){
						board.recCp.reset();
						board.pika++;
						if(typePikaLast == item1.type){
							combo++;							
							board.combo+=combo;
						}			
						else{
							combo = 0;							
						}						
						if(board.isBot == false){
							board.screen.ctr.a.eatSound[combo].play(board.screen.ctr.a.vls);
						}
						typePikaLast = item1.type;
						board.dataMap.countDown(item.type);
						board.dataMap.map[item1.row][item1.col].setSelect(false);
						board.dataMap.map[item2.row][item2.col].setSelect(false);
						board.dataMap.map[item1.row][item1.col].set(-1);
						board.dataMap.map[item2.row][item2.col].set(-1);						
						
						board.animationEat.start(typePikaLast, item1.row, item1.col, item2.row, item2.col);
						item1 = null;
						item2 = null;
					}
					else{
						//handler.wrongChoice.play(handler.isSound?1f:0f);
						if(board.isBot == false){
							board.screen.ctr.a.wrongSound.play(board.screen.ctr.a.vls);
						}
						board.dataMap.map[item1.row][item1.col].setSelect(false);
						item1 = item2;
						item2 = null;
						board.dataMap.map[item1.row][item1.col].setSelect(true);
					}
				}
				else{
					//handler.wrongChoice.play(handler.isSound?1f:0f);
					if(board.isBot == false){
						board.screen.ctr.a.wrongSound.play(board.screen.ctr.a.vls);
					}
					board.dataMap.map[item1.row][item1.col].setSelect(false);
					item1 = item2;
					item2 = null;
					board.dataMap.map[item1.row][item1.col].setSelect(true);
				}
			}
		}
		else{
			if(board.isBot == false){
				board.screen.ctr.a.selectSound.play(board.screen.ctr.a.vls);
			}
			item1 = item;
			item1.setSelect(true);
		}
	}
}
